import React from 'react';
// import { Icon } from 'antd';
import { withRouter } from 'umi';

// import pic from '@/pages/RecruitEmail/images/interview-bg-refuse.png';
// import { getLoginInfo } from '@/pages/RecruitEmail/service/interview';
// import { useRequest, defaultFormatResult } from '@/hooks';
import EntryGuide from '@/pages/EntryManage/EntryGuide/EntryGuide';
import { Header } from './components';
import styles from './index.less';
import {
    InterviewCandidate,
    InterviewHomeWork,
    InterviewInvitation,
    InterviewJoin,
    InterviewOffer,
    InterviewOut,
    InterviewOutDate
} from './pc/components';
import { RecruitContext } from './Context';
// const { Step } = Steps;

function RecruitEmailPc(props) {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { data, current, setCurrent, id, entryStatus, setEntryStatus, steps, getTotalDesc } = props;
    // const [canGoNext, setCanGoNext] = React.useState(false); // 能否往下走
    // const data = { hasValid: false, hrDetailVO: { name: '', phone: '', email: '' } };
    const handleChange = cur => {
        // steps.forEach((currStep, index) => {
        //     if (index === data.linkStep - 1) {
        //         currStep.status = 'process';
        //     } else {
        //         currStep.status = 'finish';
        //     }
        //     // if (index === res.linkStep - 1) {
        //     //     currStep.status = 'process';
        //     // } else if (index > res.linkStep - 1) {
        //     //     currStep.status = 'wait';
        //     // } else {
        //     //     currStep.status = 'finish';
        //     // }
        // });
        setCurrent(cur);
    };
    // const { data: loginInfo, run: getInfo } = useRequest(() => getLoginInfo(candidateLinkId), {
    //     manual: true,
    //     initialData: null,
    //     ...defaultFormatResult
    // });
    // React.useEffect(() => {
    //     // 面试作业
    //     if (data?.interviewWay === 5 || data?.linkStep === 2) {
    //         setCanGoNext(false);
    //         getInfo();
    //     } else {
    //         setCanGoNext(true);
    //     }
    // }, [data]);
    // React.useEffect(() => {
    //     if (loginInfo) {
    //         if (loginInfo?.wasLoginIn) {
    //             setCanGoNext(true);
    //         } else {
    //             history.push({
    //                 pathname: '/recruitment/login',
    //                 query: {
    //                     candidateLinkId,
    //                     id: candidateLinkId,
    //                     redirect: '/recruitment'
    //                 }
    //             });
    //         }
    //     }
    // }, [loginInfo]);
    const currentView = React.useMemo(() => {
        let view = null;
        switch (current) {
            case 0:
                if (data?.interviewWay === 5) {
                    view = <InterviewHomeWork nid={data?.interviewNoticeId} id={id} />;
                } else {
                    view = <InterviewInvitation nid={data?.interviewNoticeId} id={id} />;
                }

                break;
            case 1:
                view = (
                    <InterviewCandidate
                        nid={data?.signCandidateId}
                        id={id}
                        // backgroundNum={data?.backgroundNum}
                        needBackgroundFlag={data?.needBackgroundFlag}
                    />
                );
                break;
            case 2:
                if (entryStatus === 'init') {
                    view = <InterviewOffer nid={data?.employId} id={id} />;
                } else if (data?.entryPersonnelCode) {
                    view = <InterviewJoin nid={data?.employId} id={id} getTotalDesc={getTotalDesc} />;
                }

                break;
            case 3:
                view = <EntryGuide entryPersonnelCode={data?.entryPersonnelCode} />;
                break;
            default:
                break;
        }
        return view;
    }, [current, data, entryStatus]);
    // 淘汰
    if (data?.hasEliminate) {
        return (
            <div className={styles.pageWrap}>
                <Header />
                <div className={styles.contentWrap}>
                    <div className={styles.content}>
                        <InterviewOut jobName={data?.dutyName} />
                    </div>
                </div>
            </div>
        );
    }
    return (
        <div className={styles.pageWrap}>
            <Header />
            {data?.hasValid && (
                <>
                    {/* <div style={{ margin: '24px auto', maxWidth: 1080 }}>
                        <Steps current={current} onChange={handleChange}>
                            {steps.map((item, index) => (
                                <Step key={item.title} title={item.title} disabled={index >= data?.linkStep} />
                            ))}
                        </Steps>
                    </div> */}

                    <div className={styles.contentWrap}>
                        <RecruitContext.Provider value={{ ...props, handleChange }}>
                            <div className={styles.content}>{currentView}</div>
                        </RecruitContext.Provider>
                    </div>
                </>
            )}
            {data && !data.hasValid && (
                <div className={styles.contentWrap}>
                    <div className={styles.content}>
                        <InterviewOutDate data={data?.hrDetailVO} />
                    </div>
                </div>
                // <div
                //     style={{
                //         width: 600,
                //         margin: '80px auto auto auto',
                //         display: 'flex',
                //         flexDirection: 'column',
                //         alignItems: 'center'
                //     }}
                // >
                //     <img alt="" src={pic} style={{ width: 360 }} />
                //     <div style={{ marginTop: 39 }}>
                //         <Icon
                //             type="frown"
                //             theme="filled"
                //             style={{ color: '#BCC1CD', fontSize: '29px', marginRight: 21 }}
                //         />
                //         <span
                //             style={{
                //                 fontWeight: 600,
                //                 fontFamily: 'PingFangSC-Medium',
                //                 fontSize: '24px',
                //                 color: 'rgba(0,0,0,0.85)'
                //             }}
                //         >
                //             超过有效期，链接已失效
                //         </span>
                //     </div>
                // </div>
            )}
        </div>
    );
}

export default withRouter(RecruitEmailPc);
